﻿
namespace HSS.Xaml.UI.Data
{
	#region Using Directives
	using System;
	using System.Windows;
	using System.Windows.Data;
	using System.Windows.Media;
	#endregion

	#region BackgroundColorToRadialGradient
	/// <summary>
	/// BackgroundColorToRadialGradient used for the ChildWindow background.
	/// </summary>
	public sealed class BackgroundColorToRadialGradient : IValueConverter
	{
		/// <summary>
		/// Converts the provided value of type Color to a <see cref="RadialGradientBrush"/>.
		/// </summary>
		/// <param name="value">A <see cref="Color"/> value.</param>
		/// <param name="targetType">Not used.</param>
		/// <param name="parameter">Not used.</param>
		/// <param name="culture">Not used.</param>
		/// <returns>A <see cref="RadialGradientBrush"/>.</returns>
		public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			//<RadialGradientBrush GradientOrigin="0.5,0.5">
			//    <RadialGradientBrush.RelativeTransform>
			//        <TransformGroup>
			//            <ScaleTransform CenterY="0.5" CenterX="0.5" ScaleY="1.75" ScaleX="1.75"/>
			//            <SkewTransform CenterY="0.5" CenterX="0.5"/>
			//            <RotateTransform CenterY="0.5" CenterX="0.5"/>
			//            <TranslateTransform Y="0.175"/>
			//        </TransformGroup>
			//    </RadialGradientBrush.RelativeTransform>
			//    <GradientStop Color="{TemplateBinding BackgroundColor}" Offset="0.75"/>
			//    <GradientStop Color="#9FFFFFFF" Offset="1"/>
			//</RadialGradientBrush>

			var transform = new TransformGroup();
			transform.Children.Add(new ScaleTransform { CenterY = 0.5, CenterX = 0.5, ScaleY = 1.75, ScaleX = 1.75 });
			transform.Children.Add(new SkewTransform { CenterY = 0.5, CenterX = 0.5 });
			transform.Children.Add(new RotateTransform { CenterY = 0.5, CenterX = 0.5, });
			transform.Children.Add(new TranslateTransform { Y = 0.175 });

			var brush = new RadialGradientBrush();
			brush.GradientOrigin = new Point(0.5, 0.5);
			brush.GradientStops.Add(new GradientStop { Color = (Color)value, Offset = 0.75 });
			brush.GradientStops.Add(new GradientStop { Color = Color.FromArgb(159, 255, 255, 255), Offset = 1 });
			brush.RelativeTransform = transform;

			return brush;
		}
		/// <summary>
		/// Not used.
		/// </summary>
		/// <param name="value"></param>
		/// <param name="targetType"></param>
		/// <param name="parameter"></param>
		/// <param name="culture"></param>
		/// <returns></returns>
		public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
		{
			throw new NotImplementedException();
		}
	}
	#endregion
}
